package com.hee.erp.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hee.erp.modules.entity.SysUserCertificate;
import com.hee.erp.modules.mapper.SysUserCertificateMapper;
import com.hee.erp.modules.service.ISysUserCertificateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author weizehong
 * @since 2022-03-06
 */
@Service
@Transactional
public class SysUserCertificateServiceImpl extends ServiceImpl<SysUserCertificateMapper, SysUserCertificate> implements ISysUserCertificateService {

    @Override
    public List<SysUserCertificate> listByUserId(String userId) {
        LambdaQueryWrapper<SysUserCertificate> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUserCertificate::getUserId, userId);
        return this.list(queryWrapper);
    }

    @Override
    public List<SysUserCertificate> saveUserCertificates(List<SysUserCertificate> list) {

        for (SysUserCertificate sysUserCertificate : list) {
            if (sysUserCertificate.getId().contains("-")) {
                //新增
                sysUserCertificate.setId(null);
                this.save(sysUserCertificate);
            } else {
                //修改
                this.updateById(sysUserCertificate);
            }
        }

        return list;
    }
}
